using System;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class value_class
{
	public List<float> value;

	public List<Vector2> value_multi;

	public List<float> select_value;

	public List<bool> active;

	public List<Rect> rect;

	public List<string> text;

	public bool value_active;

	public float value_total;

	public int active_total;

	public AnimationCurve curve;

	public animation_curve_math_class animation_curve_math;

	public SliderMode_Enum mode;

	public value_class()
	{
		value = new List<float>();
		value_multi = new List<Vector2>();
		select_value = new List<float>();
		active = new List<bool>();
		rect = new List<Rect>();
		text = new List<string>();
		value_active = true;
		curve = new AnimationCurve();
		animation_curve_math = new animation_curve_math_class();
	}

	public void calc_active_total()
	{
		active_total = 0;
		for (int i = 0; i < value.Count; i++)
		{
			if (active[i])
			{
				value_total += value[i];
				active_total++;
			}
		}
	}

	public int calc_index(int index)
	{
		int num = 0;
		for (int i = 0; i < index; i++)
		{
			if (active[i])
			{
				num++;
			}
		}
		return num;
	}

	public void set_values(int value_index)
	{
		if (mode == SliderMode_Enum.One)
		{
			calc_value();
		}
		else
		{
			set_value_multi(value_index);
		}
	}

	public void Active(int index)
	{
	}

	public float GetPreviousValue(int index)
	{
		float result = 0f;
		for (int num = index - 1; num >= 0; num--)
		{
			if (active[num])
			{
				Vector2 vector = value_multi[num];
				result = vector.y;
				break;
			}
		}
		return result;
	}

	public int GetPreviousIndex(int index)
	{
		int num = index - 1;
		int result;
		while (true)
		{
			if (num >= 0)
			{
				if (active[num])
				{
					result = num;
					break;
				}
				num--;
				continue;
			}
			result = -1;
			break;
		}
		return result;
	}

	public float GetNextValue(int index)
	{
		float result = 0f;
		for (int i = index + 1; i < value.Count; i++)
		{
			if (active[i])
			{
				Vector2 vector = value_multi[i];
				result = vector.x;
				break;
			}
		}
		return result;
	}

	public int GetNextIndex(int index)
	{
		int num = index + 1;
		int result;
		while (true)
		{
			if (num < value.Count)
			{
				if (active[num])
				{
					result = num;
					break;
				}
				num++;
				continue;
			}
			result = value.Count;
			break;
		}
		return result;
	}

	public void calc_value()
	{
		value_total = 0f;
		float num = 0f;
		int num2 = default(int);
		calc_active_total();
		Keyframe[] array = new Keyframe[active_total + 1];
		int num3 = default(int);
		num3 = 0;
		if (mode == SliderMode_Enum.One)
		{
			for (num2 = 0; num2 < value.Count; num2++)
			{
				if (active[num2])
				{
					array[num3].value = 1f / ((float)active_total * 1f) * (float)(num3 + 1);
					array[num3].time = num + value[num2] / value_total;
					select_value[num2] = (num * 2f + value[num2] / value_total) / 2f;
					text[num2] = "(" + num.ToString("F2") + "-" + array[num3].time.ToString("F2") + ")";
					num = array[num3].time;
					num3++;
				}
				else
				{
					text[num2] = "(- )";
				}
			}
		}
		else
		{
			for (num2 = 0; num2 < value.Count; num2++)
			{
				if (active[num2])
				{
					array[num3].value = 1f / ((float)active_total * 1f) * (float)(num3 + 1);
					ref Keyframe reference = ref array[num3];
					Vector2 vector = value_multi[num2];
					reference.time = vector.y / 100f;
					if (array[num3].time == num)
					{
						if (!(array[num3].time < 1f))
						{
							array[num3 - 1].time = array[num3 - 1].time - 0.01f;
						}
						else
						{
							array[num3].time = array[num3].time + 0.01f;
						}
					}
					text[num2] = "(" + num.ToString("F2") + "-" + array[num3].time.ToString("F2") + ")";
					num = array[num3].time;
					num3++;
				}
				else
				{
					text[num2] = "(- )";
				}
			}
		}
		curve = animation_curve_math.set_curve_linear(new AnimationCurve(array));
	}

	public void set_value_multi(int index)
	{
		if (value.Count == 0)
		{
			return;
		}
		calc_active_total();
		Vector2 vector = value_multi[index];
		float y = vector.y;
		Vector2 vector2 = value_multi[index];
		if (!(y >= vector2.x))
		{
			List<Vector2> list = value_multi;
			Vector2 vector3 = value_multi[index];
			float x = vector3.x;
			Vector2 vector4 = value_multi[index];
			list[index] = new Vector2(x, vector4.x + 0.5f);
		}
		int num = default(int);
		int num2 = 0;
		for (num = 0; num < value.Count; num++)
		{
			if (!active[num] && num > 0)
			{
				num2++;
				continue;
			}
			if (num > index)
			{
				List<Vector2> list2 = value_multi;
				int index2 = num;
				Vector2 vector5 = value_multi[num - 1 - num2];
				float y2 = vector5.y;
				Vector2 vector6 = value_multi[num];
				list2[index2] = new Vector2(y2, vector6.y);
				Vector2 vector7 = value_multi[num];
				float x2 = vector7.x;
				Vector2 vector8 = value_multi[num];
				if (!(x2 <= vector8.y))
				{
					List<Vector2> list3 = value_multi;
					int index3 = num;
					Vector2 vector9 = value_multi[num];
					float x3 = vector9.x;
					Vector2 vector10 = value_multi[num];
					list3[index3] = new Vector2(x3, vector10.x + 0.5f);
				}
			}
			num2 = 0;
		}
		num2 = 0;
		if (index > 0)
		{
			for (num = index - 1; num >= 0; num--)
			{
				if (!active[num])
				{
					num2++;
				}
				else
				{
					List<Vector2> list4 = value_multi;
					int index4 = num;
					Vector2 vector11 = value_multi[num];
					float x4 = vector11.x;
					Vector2 vector12 = value_multi[num + 1 + num2];
					list4[index4] = new Vector2(x4, vector12.x);
					Vector2 vector13 = value_multi[num];
					float y3 = vector13.y;
					Vector2 vector14 = value_multi[num];
					if (!(y3 >= vector14.x))
					{
						List<Vector2> list5 = value_multi;
						int index5 = num;
						Vector2 vector15 = value_multi[num];
						float x5 = vector15.y - 0.5f;
						Vector2 vector16 = value_multi[num];
						list5[index5] = new Vector2(x5, vector16.y);
					}
					num2 = 0;
				}
			}
		}
		int num3 = 0;
		for (num = 0; num < value.Count; num++)
		{
			if (active[num])
			{
				if (num3 == 0)
				{
					List<Vector2> list6 = value_multi;
					int index6 = num;
					float x6 = 0f;
					Vector2 vector17 = value_multi[num];
					list6[index6] = new Vector2(x6, vector17.y);
				}
				if (num3 == active_total - 1)
				{
					List<Vector2> list7 = value_multi;
					int index7 = num;
					Vector2 vector18 = value_multi[num];
					list7[index7] = new Vector3(vector18.x, 100f);
				}
				num3++;
			}
		}
		calc_value();
	}

	public void reset_values()
	{
		if (mode == SliderMode_Enum.One)
		{
			for (int i = 0; i < value.Count; i++)
			{
				value[i] = 50f;
			}
		}
		else
		{
			reset_value_multi();
		}
		calc_value();
	}

	public void reset_value_multi()
	{
		int num = 0;
		int num2 = 0;
		Vector2 vector = default(Vector2);
		calc_active_total();
		if (active_total == 0)
		{
			return;
		}
		for (int i = 0; i < value.Count; i++)
		{
			if (active[i])
			{
				if (num2 == 0)
				{
					vector.x = 0f;
				}
				else
				{
					Vector2 vector2 = value_multi[i - 1 - num];
					vector.x = vector2.y;
				}
				vector.y = vector.x + 100f / (float)active_total;
				if (num2 == active_total)
				{
					vector.y = 100f;
				}
				value_multi[i] = vector;
				num = 0;
				num2++;
			}
			else
			{
				num++;
			}
		}
	}

	public void reset_single_value(int index)
	{
		if (mode == SliderMode_Enum.One)
		{
			value[index] = 50f;
			calc_value();
		}
		else if (active[index])
		{
			calc_active_total();
			int num = calc_index(index);
			value_multi[index] = new Vector2(1f / (float)active_total * (float)num * 100f, (1f / (float)active_total * (float)num + 1f / (float)active_total) * 100f);
			set_value_multi(index);
		}
	}

	public void change_value_active(bool invert)
	{
		for (int i = 0; i < value.Count; i++)
		{
			if (!invert)
			{
				active[i] = value_active;
			}
			else
			{
				active[i] = !active[i];
			}
		}
		set_values(0);
	}

	public void add_value(int index, float number)
	{
		value.Insert(index, number);
		if (index > 0)
		{
			value_multi.Insert(index, new Vector2(100f, 100f));
		}
		else
		{
			value_multi.Insert(index, new Vector2(0f, 100f));
		}
		rect.Insert(index, default(Rect));
		select_value.Insert(index, 0f);
		active.Insert(index, item: true);
		text.Insert(index, string.Empty);
		calc_value();
	}

	public void erase_value(int index)
	{
		value.RemoveAt(index);
		rect.RemoveAt(index);
		value_multi.RemoveAt(index);
		select_value.RemoveAt(index);
		active.RemoveAt(index);
		text.RemoveAt(index);
		if (value.Count > 0)
		{
			set_values(0);
		}
	}

	public void clear_value()
	{
		value.Clear();
		rect.Clear();
		value_multi.Clear();
		select_value.Clear();
		active.Clear();
		text.Clear();
	}

	public void SyncValueMulti()
	{
		int num = value.Count - value_multi.Count;
		for (int i = 0; i < num; i++)
		{
			if (i > 0)
			{
				value_multi.Add(new Vector2(100f, 100f));
			}
			else
			{
				value_multi.Add(new Vector2(0f, 100f));
			}
			rect.Add(default(Rect));
		}
		if (num != 0)
		{
			reset_value_multi();
		}
	}

	public void swap_value(int index1, int index2)
	{
		float num = value[index1];
		float num2 = select_value[index1];
		bool flag = active[index1];
		value[index1] = value[index2];
		select_value[index1] = select_value[index2];
		active[index1] = active[index2];
		value[index2] = num;
		select_value[index2] = num2;
		active[index2] = flag;
		calc_value();
	}
}
